package com.lnsf.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lnsf.entity.Category;
import com.lnsf.service.ICategoryService;


@Controller
@RequestMapping("/category")
public class CategoryController {
	
	/**
	 * CategoryController
	 * 实现商品分类的增删改查
	 * @author 小曾
	 * 2017-7-26
	 */
	
	@Autowired
	private ICategoryService iCategoryService;
	
	@ResponseBody
	@RequestMapping("/findAllCategory")
	public String findAllCategory(){
		Iterable<Category> category = iCategoryService.getAllCategory();
		for(Category cate :category ){
	        System.out.println("findAllCategory :  "+cate);
		}
		return "success";	
	}
	
	@ResponseBody
	@RequestMapping("/findCategory")
	public String findCategory(int id){
		Category category = iCategoryService.getCategory(id);
		System.out.println("findCategory :  "+category);
		return "success";	
	}
	
	@ResponseBody
	@RequestMapping("/saveCategory")
	public String saveCategory(Category category){
		Category categorys = iCategoryService.saveCategory(category);
		System.out.println("saveCategory :  "+categorys);
		return "success";	
	}
	
	@ResponseBody
	@RequestMapping("/deleteCategory")
	public String deleteCategory(int id){
		iCategoryService.deleteCategory(id);;
		System.out.println("deleteCategory success  ");
		return "success";	
	}
	
	@ResponseBody
	@RequestMapping("/updateCategory")
	public String updateCategory(int id,String name){
		int result = iCategoryService.updateCategory(id,name);
		System.out.println("updateCategory success : "+result);
		return "success";	
	}

}
